package io.gitee.xyuesheng.day03;

import org.junit.Test;

public class TestStudent {
    @Test
    public void test() {
        Student student = new Student();
        Student student2 = new Student();
        student2.changePassword("234");
        // Student zhangsan = new Student("张三");
    }

    @Test
    public void test2() {
        Teacher teacher = new Teacher();
    }

    @Test
    public void testThis() {
        Student s = new Student("zhangsan");
        s.changePassword("123");

        Student s2 = new Student("lisi");
        s2.changePassword("345");
    }

    @Test
    public void testInit() {
        Student s = new Student();

        System.out.println(s);      // 调用对象的toString()方法
    }

    // 静态域，对一个类的所有的实例来讲，在内存里面都只有一份
    @Test
    public void testStaticField() {
        Student s = new Student();

        System.out.println(s.id);

        Student s2 = new Student();
        System.out.println(s2.id);

        s.id++;

        System.out.println(s2.id);

        s2.id++;
        System.out.println(s.id);

        // 通过类，直接访问静态域
        System.out.println(Student.id);
    }

    @Test
    public void testIntanceField() {
        Student s1 = new Student();
        s1.age = 18;

        Student s2 = new Student();
        s2.age = 20;

        System.out.println(s1.age);
        System.out.println(s2.age);
    }
}
